﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Library;
using System.Data;

/*
-- =============================================
-- Author:		Duong Hoang Vinh
-- Create date: 9/11/2011
-- Description:	CategoryOrder Class
-- =============================================
*/

namespace BusinessLayer
{
   public class CategoryOrder
    {
    #region "Variables and Properties"
    //Variables
        private string category_ID;        
        private int order_Number;        
        private int del_Status;        
    //Properties
        public string Category_ID
        {
            get { return category_ID; }
            set { category_ID = value; }
        }

        public int Order_Number
        {
            get { return order_Number; }
            set { order_Number = value; }
        }

        public int Del_Status
        {
            get { return del_Status; }
            set { del_Status = value; }
        }
    #endregion

    #region "Initial Methods"
        public CategoryOrder() { }

        public CategoryOrder(SqlDataReader sdr)
        {
            if (sdr != null && !sdr.IsClosed)
            {
                Category_ID = sdr.GetString(0);
                if (!sdr.IsDBNull(1))
                    Order_Number = sdr.GetInt32(1);
                if (!sdr.IsDBNull(2))
                    Del_Status = sdr.GetInt32(2);
            }
        }
    #endregion

    #region "Bussiness Methods"
    //Get All CategoryOrder
        public static List<CategoryOrder> GetAll()
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Category_Order_SHOWALL";
            List<CategoryOrder> lstCategoryOrder = new List<CategoryOrder>();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);

            while (sdr.Read())
            {
                lstCategoryOrder.Add(new CategoryOrder(sdr));
            }

            return lstCategoryOrder;
        }

    //Get One CategoryOrder
        public static CategoryOrder GetOne(int idCategoryOrder)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Category_Order_SHOWONE";
            CategoryOrder categoryOrder = new CategoryOrder();
            SqlDataReader sdr;

            dbh.AddParameter("@Category_ID", idCategoryOrder);
            sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);

            if (sdr.Read())
            {
                categoryOrder.Category_ID = sdr.GetString(0);
                if (!sdr.IsDBNull(1))
                    categoryOrder.Order_Number = sdr.GetInt32(1);
                if (!sdr.IsDBNull(2))
                    categoryOrder.Del_Status = sdr.GetInt32(2);
            }

            return categoryOrder;
        }

    //Insert CategoryOrder
        public static void Insert(CategoryOrder categoryOrder)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Category_Order_INSERT";

            dbh.AddParameter("@Order_Number", categoryOrder.Order_Number);
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

    //Update CategoryOrder
        public static void Update(CategoryOrder categoryOrder)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Category_Order_UPDATE";

            dbh.AddParameter("@Category_ID", categoryOrder.Category_ID);
            dbh.AddParameter("@Order_Number", categoryOrder.Order_Number);

            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

    //Delete CategoryOrder
        public static void Delete(int idCategoryOrder)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Category_Order_DELETE";

            dbh.AddParameter("@Category_ID", idCategoryOrder);
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
    #endregion
    }
}
